package server

import (
	"time"
	"wths/wthsjy-im/plugins/log"
	"wths/wthsjy-im/protocol/protocolpb"
)

type MyHandler struct {
}

func (m *MyHandler) Connect(connect *protocolpb.Connect) (clientId string, pass bool) {
	log.Debug("#Connect").Msg(clientId, connect.GetToken())
	return connect.GetToken(), true
}
func (m *MyHandler) Disconnect(clientId string, info *protocolpb.DisConnect) {
	log.Debug("#Disconnect").Msg(clientId, info.String())
}
func (m *MyHandler) Ping(clientId string, info *protocolpb.Ping) {
	log.Debug("#Ping").Msg(clientId, info.String())
}
func (m *MyHandler) Publish(clientId string, info *protocolpb.Publish) {
	log.Debug("#Publish").Msg(clientId, info.String())
}
func (m *MyHandler) Subscribe(clientId string, info *protocolpb.Subscribe) map[string]bool {
	log.Debug("#Subscribe").Msg(clientId, info.String(), time.Now().String())
	mp := map[string]bool{}
	for _, v := range info.TopicNames {
		mp[v] = true
	}
	return mp
}
func (m *MyHandler) UnSubscribe(clientId string, info *protocolpb.Unsubscribe) map[string]bool {
	log.Debug("#UnSubscribe").Msg(clientId, info.String())
	mp := map[string]bool{}
	for _, v := range info.TopicNames {
		mp[v] = true
	}
	return mp
}
